Imports System.Collections.Generic
Imports System.Text

Namespace Core
	<Record(FieldMapping := FieldMapping.ExplicitColumnsOnly)> _
	Friend NotInheritable Class NdxEntry
        <Column(AdvancedType:=AdvancedColumnType.Int32)> _
        Friend mNdxNativeLowerPageNo As Int32

        <Column(AdvancedType:=AdvancedColumnType.Int32)> _
        Public DbfRecordNo As Int32

        Private mFields As SortFields

        Public Property Fields() As SortFields
            Get
                Return mFields
            End Get
            Set(value As SortFields)
                If mFields Is value Then
                    Return
                End If
                mFields = value
            End Set
        End Property

        'public byte[] RecordBuffer;

        Public Property LowerPageRecordNo() As Int32
            Get
                Return mNdxNativeLowerPageNo - 1
            End Get
            Set(value As Int32)
                mNdxNativeLowerPageNo = value + 1
            End Set
        End Property

		Public Function ChainCompare(cmp As Integer(), index As NdxFile, other As NdxEntry) As Integer
			Me.Fields.ChainCompare(other.Fields, cmp)
			' to do check for ascending descending
			For i As Integer = 0 To cmp.Length - 1
				If cmp(i) <> 0 Then
					Return cmp(i)
				End If
			Next
			' if we're here the fields are identical
			' we compare RecordNo when the index is NOT unique
			If index.mNdxHeader.UniqueFlag Then
				Return 0
			Else
				Return DbfRecordNo.CompareTo(other.DbfRecordNo)
			End If

		End Function

		Public Overrides Function ToString() As String
			Return Fields.ToString() & " " & DbfRecordNo.ToString()
		End Function
	End Class
End Namespace
